// Copyright 叶湘 ( weixin:yexiang841, email:yexiang841@qq.com ), Shitouren Studio. All Rights Reserved.

#include "Property/Q3D_CPPU_PropertyPLIPro.h"

UQ3D_CPPU_PropertyPLIPro::UQ3D_CPPU_PropertyPLIPro()
{
}

UQ3D_CPPU_PropertyPLIPro::~UQ3D_CPPU_PropertyPLIPro()
{
}

void UQ3D_CPPU_PropertyPLIPro::_F_HitHalo_Value_Cal(TMap<FName, UQ3D_CPPU_Hit *> &map_name_to_ptr_u_hit_halo, int32 &int_value_out, FString &string_log) const
{
    int32 int_value_out_tmp = 0;
    FString string_log_tmp = "";
    // 取 Value 数组
    TArray<UQ3D_CPPU_Hit *> array_values;
    map_name_to_ptr_u_hit_halo.GenerateValueArray(array_values);
    // 遍历查找
    for (UQ3D_CPPU_Hit *one : array_values)
    {
        int32 int_value_one;
        one->Q3D_F_HitValue_Get(int_value_one);
        int_value_out_tmp += int_value_one;
        string_log_tmp += "+" + FString::FromInt(int_value_one);
    }
    int_value_out = int_value_out_tmp;
    string_log = string_log_tmp;
    return;
}

void UQ3D_CPPU_PropertyPLIPro::_F_ValuePro_Reset(FString &string_log)
{
    FString string_log_tmp = StaticEnum<EQ3D_CPPE_PropertyName>()->GetNameStringByValue((uint32)(this->Enum_PropertyName)) + "_ValueProReset_" + this->Q3D_F_ToString_Pro() + "_To_";
    FString string_verbose_tmp = "";
    int32 int_hit_value_damage;
    FString string_hit_value_damage;
    this->_F_HitHalo_Value_Cal(this->Map_Name_To_Ptr_U_HitDamageHalo, int_hit_value_damage, string_hit_value_damage);
    int32 int_hit_value_recover;
    FString string_hit_value_recover;
    this->_F_HitHalo_Value_Cal(this->Map_Name_To_Ptr_U_HitRecoverHalo, int_hit_value_recover, string_hit_value_recover);
    string_verbose_tmp += string_hit_value_damage + string_hit_value_recover;
    bool bool_change;
    this->_F_Limit_Check(this->Int_Value + int_hit_value_recover - int_hit_value_damage, this->Int_ValuePro, bool_change);
    // 处理 Max==Value==Min==0 的可能
    if (this->Int_Max == 0)
    {
        this->Int_Percent = 0;
        this->Float_Percent = 0;
    }
    else
    {
        this->Int_Percent = (int32)(100.f * ((float)(this->Int_ValuePro)) / ((float)(this->Int_Max)));
        this->Float_Percent = (float)(this->Int_Percent) / 100.f;
    }
    string_log_tmp += this->Q3D_F_ToString_Pro();
    Q3D_ED_ValuePro_Reset.Broadcast(this);
    if (this->Int_ValuePro == this->Int_Min)
    {
        Q3D_ED_ValuePro_ReachMin.Broadcast(this);
    }
    if (this->Int_ValuePro == this->Int_Max)
    {
        Q3D_ED_ValuePro_ReachMax.Broadcast(this);
    }
    string_log = string_log_tmp;
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_Limit_Set(int32 int_min_in, int32 int_max_in, bool &bool_success, FString &string_log)
{
    Super::Q3D_F_Limit_Set(int_min_in, int_max_in, bool_success, string_log);
    if (!bool_success)
    {
        return;
    }
    this->_F_ValuePro_Reset(string_log);
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_Max_Set(int32 int_max_in, bool &bool_success, FString &string_log)
{
    Super::Q3D_F_Max_Set(int_max_in, bool_success, string_log);
    if (!bool_success)
    {
        return;
    }
    this->_F_ValuePro_Reset(string_log);
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_Max_SetScale(int32 int_max_in, bool &bool_success, FString &string_log)
{
    Super::Q3D_F_Max_SetScale(int_max_in, bool_success, string_log);
    if (!bool_success)
    {
        return;
    }
    this->_F_ValuePro_Reset(string_log);
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_Value_Dec(int32 int_value_dec)
{
    Super::Q3D_F_Value_Dec(int_value_dec);
    FString string_log;
    this->_F_ValuePro_Reset(string_log);
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_Value_Inc(int32 int_value_inc)
{
    Super::Q3D_F_Value_Inc(int_value_inc);
    FString string_log;
    this->_F_ValuePro_Reset(string_log);
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_Value_Set(int32 int_value_in)
{
    Super::Q3D_F_Value_Set(int_value_in);
    FString string_log;
    this->_F_ValuePro_Reset(string_log);
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_Value_SetRandom()
{
    Super::Q3D_F_Value_SetRandom();
    FString string_log;
    this->_F_ValuePro_Reset(string_log);
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_FD_Max_Set_Pro(UQ3D_CPPU_PropertyPLIPro *ptr_u_property_pli_pro)
{
    bool bool_success;
    FString string_log;
    this->Q3D_F_Max_Set(ptr_u_property_pli_pro->Int_ValuePro, bool_success, string_log);
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_FD_Max_SetScale_Pro(UQ3D_CPPU_PropertyPLIPro *ptr_u_property_pli_pro)
{
    bool bool_success;
    FString string_log;
    this->Q3D_F_Max_SetScale(ptr_u_property_pli_pro->Int_ValuePro, bool_success, string_log);
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_HitHalo_Inc(UQ3D_CPPU_Hit *ptr_u_hit, bool &bool_success, FString &string_log)
{
    if (ptr_u_hit->Q3D_F_HitMode_GetEnum() != EQ3D_CPPE_HitMode::Halo_Const && ptr_u_hit->Q3D_F_HitMode_GetEnum() != EQ3D_CPPE_HitMode::Halo_Timed)
    {
        bool_success = false;
        string_log = "Invalid_Enum_HitMode";
        return;
    }
    switch (ptr_u_hit->Q3D_F_HitType_GetEnum())
    {
    case EQ3D_CPPE_HitType::Damage:
        Map_Name_To_Ptr_U_HitDamageHalo.Add(ptr_u_hit->Name_Id, ptr_u_hit);
        break;
    case EQ3D_CPPE_HitType::Recover:
        Map_Name_To_Ptr_U_HitRecoverHalo.Add(ptr_u_hit->Name_Id, ptr_u_hit);
        break;
    default:
        break;
    }
    bool_success = true;
    this->_F_ValuePro_Reset(string_log);
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_HitHalo_Dec(FName name_id, EQ3D_CPPE_HitType enum_hit_type, bool &bool_success, FString &string_log)
{
    switch (enum_hit_type)
    {
    case EQ3D_CPPE_HitType::Damage:
        bool_success = Map_Name_To_Ptr_U_HitDamageHalo.Remove(name_id);
        break;
    case EQ3D_CPPE_HitType::Recover:
        bool_success = Map_Name_To_Ptr_U_HitRecoverHalo.Remove(name_id);
        break;
    default:
        break;
    }
    this->_F_ValuePro_Reset(string_log);
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_HitHalo_Clear(EQ3D_CPPE_HitType enum_hit_type)
{
    switch (enum_hit_type)
    {
    case EQ3D_CPPE_HitType::Damage:
        Map_Name_To_Ptr_U_HitDamageHalo.Empty();
        break;
    case EQ3D_CPPE_HitType::Recover:
        Map_Name_To_Ptr_U_HitRecoverHalo.Empty();
        break;
    default:
        break;
    }
    FString string_log;
    this->_F_ValuePro_Reset(string_log);
    return;
}

void UQ3D_CPPU_PropertyPLIPro::Q3D_F_ToString_Pro(FString &string_min_max_base_pro) const
{
    string_min_max_base_pro = this->Q3D_F_ToString_Pro();
    return;
}

FString UQ3D_CPPU_PropertyPLIPro::Q3D_F_ToString_Pro() const
{
    return StaticEnum<EQ3D_CPPE_PropertyName>()->GetNameStringByValue((uint8)(this->Enum_PropertyName)) + "(" + FString::FromInt(this->Int_Min) + "," + FString::FromInt(this->Int_Max) + "," + FString::FromInt(this->Int_Value) + "," + FString::FromInt(this->Int_ValuePro) + ")";
}
